package com.wanshu.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wanshu.common.util.PageUtils;
import com.wanshu.sys.entity.SysLog;
import com.wanshu.sys.mapper.SysLogMapper;
import com.wanshu.sys.model.SysLogQueryDTO;
import com.wanshu.sys.service.ISysLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统日志 服务实现类
 * </p>
 *
 * @author 波哥
 * @since 2024-06-06
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements ISysLogService {

    @Override
    public PageUtils queryPage(SysLogQueryDTO queryDTO) {
        QueryWrapper<SysLog> wrapper = new QueryWrapper<SysLog>();
        if(StringUtils.isNotEmpty(queryDTO.getMsg())){
            wrapper.and(item -> item.like("username", queryDTO.getMsg()).or().
                    like("operation", queryDTO.getMsg()));
        }
        Page<SysLog> sysLogs = page(queryDTO.page(), wrapper);
        //.like("username", queryDTO.getMsg())
        return new PageUtils(sysLogs);
    }
}
